﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MinGuiLuo.MetaModel;
using UtilityLibrary.WinControls;

namespace WinFromDevelopFramework
{
    /// <summary>
    /// 工具栏帮助类
    /// </summary>
    public class OutlookBarHelper
    {
        private ImageList imglist = new ImageList();
        public void StartupEntityPlugins(OutlookBar bar)
        {
            if (bar == null && CommonModel.Modules.Count == 0) return;
            IEnumerable<ModuleMeta> list = CommonModel.Modules.GetRootsWithPermission();
            if (list.Count() > 0)
            {
                OutlookBarBand rootobb = new OutlookBarBand();
                foreach (var item in list)
                {
                    if (string.IsNullOrWhiteSpace(item.Label)) continue;
                    rootobb.Text = item.Label;
                    rootobb.Tag = item.WinFromTemplateType;
                    if (item.Image==null) item.Image = Consts.OutlookBarImgFile;
                    imglist.Images.Add(Image.FromFile(item.Image));
                    rootobb.SmallImageList = imglist;
                    rootobb.LargeImageList = imglist;
                    rootobb.Background = SystemColors.AppWorkspace;
                    rootobb.TextColor = Color.White;
                    for (int i = 0; i < item.Children.Count; i++)
                    {
                        var child = item.Children[i];
                        if (string.IsNullOrWhiteSpace(child.Label)) continue;
                        OutlookBarItem oltem = new OutlookBarItem(child.Label, i);
                        oltem.Tag = child.WinFromTemplateType;
                        if (child.Image == null) child.Image = Consts.OutlookBarImgFile;
                        imglist.Images.Add(Image.FromFile(child.Image));
                        rootobb.Items.Add(oltem);
                    }
                }
                bar.Bands.Add(rootobb);
                bar.Dock = DockStyle.Fill;
                bar.SetCurrentBand(0);
                //bar.ItemClicked += new OutlookBarItemClickedHandler(OnOutlookBarItemClicked);
            }
        }
        private void OnOutlookBarItemClicked(OutlookBarBand band, OutlookBarItem item)
        {
            if (item.Tag != null)
            {
                var type = (Type)item.Tag;
            }
        }
    }
}
